package com.panopset.fundraw;

public abstract class Sprite {

    protected abstract int getRadius();
    protected abstract int[] getLocation();

    protected Integer x, y, x0, x1, y0, y1;
    public Integer getX0() {
        if (x0 == null) {
            calculateBounds();
        }
        return x0;
    }
    public Integer getX1() {
        if (x1 == null) {
            calculateBounds();
        }
        return x1;
    }
    public Integer getY0() {
        if (y0 == null) {
            calculateBounds();
        }
        return y0;
    }
    public Integer getY1() {
        if (y1 == null) {
            calculateBounds();
        }
        return y1;
    }

    public Integer getHeight() {
        return getWidth();
    }

    private Integer width;
    public Integer getWidth() {
        if (width == null) {
            calculateBounds();
            width = getRadius() * 2;
        }
        return width;
    }

    protected void calculateBounds() {
        x = getLocation()[0];
        y = getLocation()[1];
        x0 = x - getRadius();
        x1 = x + getRadius();
        y0 = y - getRadius();
        y1 = y + getRadius();
    }

    public boolean collidedWith(Sprite o) {
        return ((o.x-x)^2 + (o.y-y)^2) <= ((getRadius()+getRadius())^2);
    }

}
